package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraStorageStrategyTimeslotRelationCreateReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraStorageStrategyTimeslotRelationUpdateReqDTO;
import com.yc.cloud.admin.vo.HwCameraStorageStrategyTimeslotRelationVo;
import com.yc.cloud.admin.service.HwCameraStorageStrategyTimeslotRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

/**
 * <p>
 * 存储策略时间段关联表 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-09-17
 */
@RestController
@Api(tags = "存储策略时间段关联表")
@RequestMapping("/hw-camera-storage-strategy-timeslot-relations")
public class HwCameraStorageStrategyTimeslotRelationController {

    @Resource
    private HwCameraStorageStrategyTimeslotRelationService hwCameraStorageStrategyTimeslotRelationService;

    @ApiOperation("创建存储策略时间段关联表")
    @PostMapping
    public ResponseResult<HwCameraStorageStrategyTimeslotRelationVo> create(@Validated @RequestBody HwCameraStorageStrategyTimeslotRelationCreateReqDTO createReqDTO) {
        HwCameraStorageStrategyTimeslotRelationVo newVo = hwCameraStorageStrategyTimeslotRelationService.create(createReqDTO);
        if (newVo != null) {
            return ResponseResult.success(newVo);
        }
        return ResponseResult.failed("创建失败");
    }

    @ApiOperation("更新存储策略时间段关联表")
    @PutMapping("/{id}")
    public ResponseResult<HwCameraStorageStrategyTimeslotRelationVo> update(@PathVariable("id") Long id, @Validated @RequestBody HwCameraStorageStrategyTimeslotRelationUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        HwCameraStorageStrategyTimeslotRelationVo updatedVo = hwCameraStorageStrategyTimeslotRelationService.update(updateReqDTO);
        if (updatedVo != null) {
            return ResponseResult.success(updatedVo);
        }
        return ResponseResult.failed("更新失败");
    }

    @ApiOperation("删除存储策略时间段关联表")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = hwCameraStorageStrategyTimeslotRelationService.delete(id);
        if (success) {
            return ResponseResult.success(true);
        }
        return ResponseResult.failed("删除失败");
    }

    @ApiOperation("获取存储策略时间段关联表详情")
    @GetMapping("/{id}")
    public ResponseResult<HwCameraStorageStrategyTimeslotRelationVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(hwCameraStorageStrategyTimeslotRelationService.getVOById(id));
    }

    @ApiOperation("分页查询存储策略时间段关联表")
    @GetMapping
    public ResponseResult<CommonPage<HwCameraStorageStrategyTimeslotRelationVo>> list(@Validated BasePageReqDTO pageReqDTO) {
        return ResponseResult.success(hwCameraStorageStrategyTimeslotRelationService.list(pageReqDTO));
    }
}
 